'DateFormatter' => __DIR__ . '/includes/parser/DateFormatter.php',
'DeadendPagesPage' => __DIR__ . '/includes/specials/SpecialDeadendpages.php',
'DeferrableUpdate' => __DIR__ . '/includes/deferred/DeferredUpdates.php',
- 'DeferredStringifier' => __DIR__ . '/includes/DeferredStringifier.php',
+ 'DeferredStringifier' => __DIR__ . '/includes/libs/DeferredStringifier.php',
'DeferredUpdates' => __DIR__ . '/includes/deferred/DeferredUpdates.php',
'DeleteAction' => __DIR__ . '/includes/actions/DeleteAction.php',
'DeleteArchivedFiles' => __DIR__ . '/maintenance/deleteArchivedFiles.php',
+++ /dev/null
-<?php
-/**
- * Class that defers a slow string generation until the string is actually needed.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- * @file
- */
-
-/**
- * @since 1.25
- */
-class DeferredStringifier {
- /** @var callable Callback used for result string generation */
- private $callback;
- /** @var array */
- private $params;
- /** @var string */
- private $result;
-
- /**
- * @param callable $callback Callback that gets called by __toString
- * @param mixed $param,... Parameters to the callback
- */
- public function __construct( $callback /*...*/ ) {
- $this->params = func_get_args();
- array_shift( $this->params );
- $this->callback = $callback;
- }
-
- /**
- * Returns a string generated by callback
- *
- * @return string
- */
- public function __toString() {
- if ( $this->result === null ) {
- $this->result = call_user_func_array( $this->callback, $this->params );
- }
- return $this->result;
- }
-}
if ( $action === true ) {
$action = 'byemail';
} elseif ( $action === false ) {
- if ( $this->getName() == $wgUser->getName() ) {
+ if ( $this->equals( $wgUser ) ) {
$action = 'create';
} else {
$action = 'create2';
return Status::newFatal( 'badaccess-group0' );
}
}
+
+ /**
+ * Checks if two user objects point to the same user.
+ *
+ * @since 1.25
+ * @param User $user
+ * @return bool
+ */
+ public function equals( User $user ) {
+ return $this->getName() === $user->getName();
+ }
}
}
// Users without the 'autopatrol' right can't patrol their
// own revisions
- if ( $user->getName() == $this->getAttribute( 'rc_user_text' )
+ if ( $user->getName() === $this->getAttribute( 'rc_user_text' )
&& !$user->isAllowed( 'autopatrol' )
) {
$errors[] = array( 'markedaspatrollederror-noautopatrol' );
array( 'USE INDEX' => 'rc_timestamp' )
);
- if ( $change && $change->getPerformer()->getName() !== $user->getName() ) {
+ if ( $change && !$change->getPerformer()->equals( $user ) ) {
$rcid = $change->getAttribute( 'rc_id' );
} else {
// None found or the page has been created by the current user.
--- /dev/null
+<?php
+/**
+ * Class that defers a slow string generation until the string is actually needed.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * @since 1.25
+ */
+class DeferredStringifier {
+ /** @var callable Callback used for result string generation */
+ private $callback;
+ /** @var array */
+ private $params;
+ /** @var string */
+ private $result;
+
+ /**
+ * @param callable $callback Callback that gets called by __toString
+ * @param mixed $param,... Parameters to the callback
+ */
+ public function __construct( $callback /*...*/ ) {
+ $this->params = func_get_args();
+ array_shift( $this->params );
+ $this->callback = $callback;
+ }
+
+ /**
+ * Returns a string generated by callback
+ *
+ * @return string
+ */
+ public function __toString() {
+ if ( $this->result === null ) {
+ $this->result = call_user_func_array( $this->callback, $this->params );
+ }
+ return $this->result;
+ }
+}
return false;
}
- if ( $rc->getPerformer()->getName() == $user->getName() ) {
+ if ( $rc->getPerformer()->equals( $user ) ) {
// Don't show a patrol link for own creations. If the user could
// patrol them, they already would be patrolled
return false;
$config = $this->getConfig();
if ( $config->get( 'CheckFileExtensions' ) ) {
+ $fileExtensions = array_unique( $config->get( 'FileExtensions' ) );
if ( $config->get( 'StrictFileExtensions' ) ) {
# Everything not permitted is banned
$extensionsList =
'<div id="mw-upload-permitted">' .
- $this->msg(
- 'upload-permitted',
- $this->getContext()->getLanguage()->commaList(
- array_unique( $config->get( 'FileExtensions' ) )
- )
- )->parseAsBlock() .
+ $this->msg( 'upload-permitted' )
+ ->params( $this->getLanguage()->commaList( $fileExtensions ) )
+ ->numParams( count( $fileExtensions ) )
+ ->parseAsBlock() .
"</div>\n";
} else {
# We have to list both preferred and prohibited
+ $fileBlacklist = array_unique( $config->get( 'FileBlacklist' ) );
$extensionsList =
'<div id="mw-upload-preferred">' .
- $this->msg(
- 'upload-preferred',
- $this->getContext()->getLanguage()->commaList(
- array_unique( $config->get( 'FileExtensions' ) )
- )
- )->parseAsBlock() .
+ $this->msg( 'upload-preferred' )
+ ->params( $this->getLanguage()->commaList( $fileExtensions ) )
+ ->numParams( count( $fileExtensions ) )
+ ->parseAsBlock() .
"</div>\n" .
'<div id="mw-upload-prohibited">' .
- $this->msg(
- 'upload-prohibited',
- $this->getContext()->getLanguage()->commaList(
- array_unique( $config->get( 'FileBlacklist' ) )
- )
- )->parseAsBlock() .
+ $this->msg( 'upload-prohibited' )
+ ->params( $this->getLanguage()->commaList( $fileBlacklist ) )
+ ->numParams( count( $fileBlacklist ) )
+ ->parseAsBlock() .
"</div>\n";
}
} else {
}
}
- if ( User::getCanonicalName( $this->mTarget ) == $user->getName() ) {
+ if ( User::getCanonicalName( $this->mTarget ) === $user->getName() ) {
$this->isself = true;
}
global $wgAuth;
// Validate input set...
- $isself = ( $user->getName() == $this->getUser()->getName() );
+ $isself = $user->equals( $this->getUser() );
$groups = $user->getGroups();
$changeable = $this->changeableGroups();
$addable = array_merge( $changeable['add'], $isself ? $changeable['add-self'] : array() );
"upload-summary": "",
"upload-recreate-warning": "<strong>Warning: A file by that name has been deleted or moved.</strong>\n\nThe deletion and move log for this page are provided here for convenience:",
"uploadtext": "Use the form below to upload files.\nTo view or search previously uploaded files go to the [[Special:FileList|list of uploaded files]], (re)uploads are also logged in the [[Special:Log/upload|upload log]], deletions in the [[Special:Log/delete|deletion log]].\n\nTo include a file in a page, use a link in one of the following forms:\n* <strong><code><nowiki>[[</nowiki>{{ns:file}}<nowiki>:File.jpg]]</nowiki></code></strong> to use the full version of the file\n* <strong><code><nowiki>[[</nowiki>{{ns:file}}<nowiki>:File.png|200px|thumb|left|alt text]]</nowiki></code></strong> to use a 200 pixel wide rendition in a box in the left margin with \"alt text\" as description\n* <strong><code><nowiki>[[</nowiki>{{ns:media}}<nowiki>:File.ogg]]</nowiki></code></strong> for directly linking to the file without displaying the file",
- "upload-permitted": "Permitted file types: $1.",
- "upload-preferred": "Preferred file types: $1.",
- "upload-prohibited": "Prohibited file types: $1.",
+ "upload-permitted": "Permitted file {{PLURAL:$2|type|types}}: $1.",
+ "upload-preferred": "Preferred file {{PLURAL:$2|type|types}}: $1.",
+ "upload-prohibited": "Prohibited file {{PLURAL:$2|type|types}}: $1.",
"uploadfooter": "-",
"upload-default-description": "-",
"uploadlogpage": "Upload log",
"upload-summary": "{{doc-specialpagesummary|upload}}",
"upload-recreate-warning": "Used as warning in [[Special:Upload]].",
"uploadtext": "{{doc-important|<code>thumb</code> and <code>left</code> are magic words. Leave them untranslated!}}\nText displayed when uploading a file using [[Special:Upload]].",
- "upload-permitted": "Used in [[Special:Upload]]. Parameters:\n* $1 - list of file types, defined in the variable [[mw:Special:MyLanguage/Manual:$wgFileExtensions|$wgFileExtensions]]\nSee also:\n* {{msg-mw|Upload-preferred}}\n* {{msg-mw|Upload-prohibited}}",
- "upload-preferred": "Used in [[Special:Upload]]. Parameters:\n* $1 - list of file types, defined in the variable [[mw:Special:MyLanguage/Manual:$wgFileExtensions|$wgFileExtensions]]\nSee also:\n* {{msg-mw|Upload-permitted}}\n* {{msg-mw|Upload-prohibited}}",
- "upload-prohibited": "Used in [[Special:Upload]]. Parameters:\n* $1 - list of file types, defined in the variable [[mw:Special:MyLanguage/Manual:$wgFileBlacklist|$wgFileBlacklist]]\nSee also:\n* {{msg-mw|Upload-permitted}}\n* {{msg-mw|Upload-preferred}}",
+ "upload-permitted": "Used in [[Special:Upload]]. Parameters:\n* $1 - list of file types, defined in the variable [[mw:Special:MyLanguage/Manual:$wgFileExtensions|$wgFileExtensions]]\n* $2 - count of items in $1 - for use in plural\nSee also:\n* {{msg-mw|Upload-preferred}}\n* {{msg-mw|Upload-prohibited}}",
+ "upload-preferred": "Used in [[Special:Upload]]. Parameters:\n* $1 - list of file types, defined in the variable [[mw:Special:MyLanguage/Manual:$wgFileExtensions|$wgFileExtensions]]\n* $2 - count of items in $1 - for use in plural\nSee also:\n* {{msg-mw|Upload-permitted}}\n* {{msg-mw|Upload-prohibited}}",
+ "upload-prohibited": "Used in [[Special:Upload]]. Parameters:\n* $1 - list of file types, defined in the variable [[mw:Special:MyLanguage/Manual:$wgFileBlacklist|$wgFileBlacklist]]\n* $2 - count of items in $1 - for use in plural\nSee also:\n* {{msg-mw|Upload-permitted}}\n* {{msg-mw|Upload-preferred}}",
"uploadfooter": "{{notranslate}}",
"upload-default-description": "{{ignored}}Custom default upload description. The contents of this message be will inserted in the field \"Summary\" on [[Special:Upload]].",
"uploadlogpage": "{{doc-logpage}}\n\nPage title of [[Special:Log/upload]].",
'false' => 'With / slash' ), 'With slash' ),
);
}
+
+ /**
+ * @covers User::equals
+ */
+ public function testEquals() {
+ $first = User::newFromName( 'EqualUser' );
+ $second = User::newFromName( 'EqualUser' );
+
+ $this->assertTrue( $first->equals( $first ) );
+ $this->assertTrue( $first->equals( $second ) );
+ $this->assertTrue( $second->equals( $first ) );
+
+ $third = User::newFromName( '0' );
+ $fourth = User::newFromName( '000' );
+
+ $this->assertFalse( $third->equals( $fourth ) );
+ $this->assertFalse( $fourth->equals( $third ) );
+
+ // Test users loaded from db with id
+ $user = User::newFromName( 'EqualUnitTestUser' );
+ if ( !$user->getId() ) {
+ $user->addToDatabase();
+ }
+
+ $id = $user->getId();
+
+ $fifth = User::newFromId( $id );
+ $sixth = User::newFromName( 'EqualUnitTestUser' );
+ $this->assertTrue( $fifth->equals( $sixth ) );
+ }
}
--- /dev/null
+<?php
+
+class DeferredStringifierTest extends PHPUnit_Framework_TestCase {
+
+ /**
+ * @covers DeferredStringifier
+ * @dataProvider provideToString
+ */
+ public function testToString( $params, $expected ) {
+ $class = new ReflectionClass( 'DeferredStringifier' );
+ $ds = $class->newInstanceArgs( $params );
+ $this->assertEquals( $expected, (string)$ds );
+ }
+
+ public static function provideToString() {
+ return array(
+ // No args
+ array( array( function() {
+ return 'foo';
+ } ), 'foo' ),
+ // Has args
+ array( array( function( $i ) {
+ return $i;
+ }, 'bar' ), 'bar' ),
+ );
+ }
+
+ /**
+ * Verify that the callback is not called if
+ * it is never converted to a string
+ */
+ public function testCallbackNotCalled() {
+ $ds = new DeferredStringifier( function() {
+ throw new Exception( 'This should not be reached!' );
+ } );
+ // No exception was thrown
+ $this->assertTrue( true );
+ }
+}